home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / noweb / contrib / partingr / mm2mx63 < prev    next >
Text File  |  1995-02-24  |  5KB  |  161 lines

  1. #!/usr/common/bin/perl
  2. do "getopts.pl" || die "$!";
  3. do Getopts('imnd:l:');
  4.  
  5. do "TeXthings";
  6.  
  7. $sectionref='aaa'; $i=0;
  8. if($opt_l)
  9.  { open(LOGFILE,">$opt_l") || die "$!"; }
  10.   
  11. while(<>)
  12. {
  13. #  s/\n$//;
  14.   s/^@//;
  15. # expand wildcard references here, then process as normal
  16.   if(/^(use|defn) (.*)\.{3}$/)
  17.     { print LOGFILE "Wildcard `$2...', expands to  " if $opt_l;
  18.       @matches=grep(/^$2.*/i,split(/ñ/,$known));
  19.       if($#matches>0)
  20.         { 
  21.           print LOGFILE "[",join('][',@matches),"] " if $opt_l;
  22.           print STDERR "Ambiguous module name `$mod...', line $i\n";
  23.           print STDERR "Matches: [",join('][',@matches),"]\n";
  24.           print STDERR "Using `",@matches[0],"'\n";
  25.           #die "\nAmbiguous module name `$mod...', line $i"; 
  26.         }
  27.       elsif($#matches==-1)
  28.         { 
  29.           die "\nNo match for name `$mod...', line $i";
  30.         }
  31.       $mn=@matches[0];
  32.       if($mn=~/\[\[/) { $mn=&convquotes($mn); }
  33.       print LOGFILE $mn,"\n" if $opt_l;
  34.       $_="$1 $mn";
  35.     }
  36.  
  37. # process a <<defn>>=
  38.   if(/^defn (.*)$/)
  39.     { print LOGFILE "Defining chunk `$1' with macro $sectionref\n" if $opt_l;
  40.       $md=$1; $mn=$1; if($opt_n) { $md=~tr/A-Z/a-z/; }
  41.       $mt=$md;
  42.       $mt=~s/([*+.?{}()])/\\\1/g;
  43.       if($known!~/ñ$mt/) { $known=$known . "ñ$md"; }
  44.       @names{$md}=1; $currentmod=$md;
  45.       @defines{$md}=@defines{$md} . "\\\\{\\xp\\$sectionref}";
  46.       #if($mn=~/\[\[/) { $mn=&convquotes($mn); }
  47.       @lines[$i]="defn $sectionref $mn\n"; $oldref=$sectionref;
  48.       $sectionref++;
  49.       push(@uses,$i);
  50.       $indxing=0;
  51.     }
  52. # process a <<use>>
  53.   elsif(/^use (.*)$/)
  54.     { print LOGFILE "Using chunk `$1' in chunk $oldref\n" if $opt_l;
  55.       $md=$1; $mn=$1; if($opt_n) { $md=~tr/A-Z/a-z/; }
  56.       $mt=$md;
  57.       $mt=~s/([*+.?{}()])/\\\1/g;
  58.       if($known!~/ñ$mt/) { $known=$known . "ñ$md"; }
  59.       @reference{$md}=@reference{$md} . "\\\\{\\xp\\$oldref}";
  60.       #if($mn=~/\[\[/) { $mn=&convquotes($mn); }
  61.       @lines[$i]="use $oldref $mn\n";
  62.       push(@uses,$i); 
  63.       $indxing=0;
  64.     }
  65. # process identifier information
  66.   elsif(/^index (nl|defn |use )(.*)/)
  67.     {  
  68.       if($2 eq '|') { $indxing=1; }
  69.       else
  70.       { if($2)
  71.         { print LOGFILE "Identifier `$2' indexed as " if $opt_l;
  72.           if($1 eq "defn " && !$indxing)
  73.            { print LOGFILE "defined [$oldref]\n" if $opt_l;
  74.              $style="";
  75.            }
  76.           else
  77.            { print LOGFILE "used [$oldref]\n" if $opt_l;
  78.              $style="\\it";
  79.            }
  80.           @variables{$2}=@variables{$2} . ",\\thinspace{$style\\xp\\$oldref}";
  81.         }
  82.       }
  83.       $i--; # don't put this line in the file here
  84.     }
  85. # stick the line in the array
  86.   else
  87.    { @lines[$i]=$_; }
  88.   $i++;
  89. }
  90.  
  91. if($opt_l)
  92.  {
  93.    print LOGFILE "\n\nList of modules currently defined\n";
  94.    print LOGFILE join("\n",sort keys(defines));
  95.    print LOGFILE "\n\nList of modules currently referenced\n";
  96.    print LOGFILE join("\n",sort keys(reference));
  97.    print LOGFILE "\n\n";
  98.  }
  99.  
  100. foreach(keys(reference))
  101.  { @longlist{$_}=@reference{$_}; }
  102.  
  103. foreach(keys(defines))
  104.  { @longlist{$_}=@longlist{$_} . ('%' . @defines{$_}); }
  105.  
  106. foreach(@uses)
  107.  { 
  108.    $ref=@lines[$_];
  109.    $ref=~/^(use|defn) (...) (.*)/;
  110.    $mn=$3; $dr=$2; $ac=$1;
  111.    $defns=@defines{$mn};
  112.    print LOGFILE "Module $mn " if $opt_l;
  113.    if($ac eq 'defn')
  114.     { $uses=@reference{$mn}; $uses="{$uses}|";
  115.       print LOGFILE "defined at line $_, $uses\n" if $opt_l;
  116.     }
  117.    else
  118.     { $uses=''; 
  119.       print LOGFILE "referenced at line $_\n" if $opt_l;
  120.     }
  121.    print LOGFILE "Line $_ modified to `$ac $dr {$defns} $uses$mn'\n" if $opt_l;
  122.    $mn=&convquotes($mn);
  123.    @lines[$_]="$ac $dr|{$defns}|$uses $mn\n";
  124.  }
  125.         
  126. print STDOUT "header tex \n",@lines;
  127.  
  128. # now @longlist{MOD} contains a list of all the references to <MOD>
  129. # sort them to make them look pretty
  130.  
  131. if($opt_m)
  132.   {
  133.     print LOGFILE "Making module index...\n" if $opt_l;
  134.     print "index mods\n";
  135.     foreach(sort keys(longlist))
  136.       {
  137.         $defns=@defines{$_};
  138.         $defns=~s/^,\\\\thinspace//;
  139.         print LOGFILE "Module <$_ $defns> ",@reference{$_},"\n" if $opt_l;
  140.        # first we print the module name and defining numbers
  141.         print "entry {\\LA ",&convquotes($_),"\\ \\xwp{$defns}\\RA}\\quad";
  142.        # now we print the bit after that : assume foot=cmr8
  143.         print "{\\foot\\xtc{",@reference{$_},"}}\n";
  144.       }
  145.     print "end index\n";
  146.   }
  147.  
  148. if($opt_i)
  149.   {
  150.     print "index ids\n";
  151.     foreach(sort keys(variables))
  152.      {
  153.         $vars=@variables{$_};
  154.         $vars=~s/^,\\thinspace//;
  155.         print "entry {\\code ",&TeXliteral($_),"\\edoc} :\\quad",$vars,"\n";
  156.       }
  157.     print "end index\n";
  158.   }
  159.   
  160. print STDOUT "trailer tex\n";
  161.